package com.example.sxt_practise.IO;

import java.io.*;

/**
 * @author gaofeng
 * @date 2022年05月08日 15:57
 */
public class IoTest01 {
    public static void main(String[] args) {
        // 1.创建源
        File dir = new File("dir/test2/index.html") ;
        // 2.选择流
//        InputStream fileInputStream = null;
        {
            try (InputStream fileInputStream = new BufferedInputStream(new FileInputStream(dir));) {
//                fileInputStream = new BufferedInputStream(new FileInputStream(dir));
                int read = fileInputStream.read();
                int read2 = fileInputStream.read();
                // 文件的末尾返回-1
                /*int read10 = fileInputStream.read() ;
                System.out.println((char) read);
                System.out.println((char) read2);*/
                // 3.操作
                int temp ;
                while ((temp = fileInputStream.read()) != -1) {
                    System.out.print((char) temp);
                }
                // 4.释放资源
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            } /*finally {
                if (Objects.nonNull(fileInputStream)) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }*/
        }
    }
}
